<template>
    <div class="pagination_box" v-if="totalPage && totalPage > 1">
        <span :class="pageNo != 1 && 'ups'" @click="onPage(pageNo != 1, 1)">First</span>
        <span :class="pageNo != 1 && 'ups'" @click="onPage(pageNo != 1, props.pageNo - 1)">
            <el-icon>
                <ArrowLeftBold />
            </el-icon> </span>
        <span> Page {{ pageNo }} of {{ totalPage }} </span>
        <span :class="totalPage > pageNo && 'ups'" @click="onPage(totalPage > pageNo, props.pageNo + 1)">
            <el-icon>
                <ArrowRightBold />
            </el-icon>
        </span>
        <span :class="totalPage > pageNo && 'ups'" @click="onPage(totalPage > pageNo, props.totalPage)">Last</span>
    </div>
</template>

<script setup>
import { ArrowLeftBold, ArrowRightBold } from '@element-plus/icons-vue'
import { defineEmits } from 'vue'

const emit = defineEmits(['setPage']);

const props = defineProps({
    totalPage: Number,
    pageNo: Number
});

const onPage = (flag, number) => {
    if (flag) {
        emit('setPage', number)
    }
}

</script>

<style lang="less" scopeds>
.pagination_box {
    display: flex;
    gap: 5px;
    font-size: 0.8rem;
    margin-left: 10px;

    span {
        background-color: #F8F9FA;
        display: inline-block;
        line-height: 28px;
        height: 28px;
        padding: 0 10px;
        border-radius: 4px;
        border: 1px solid #e9ecef;
        color: var(--color-text2);
        cursor: pointer;
        transition: .5s;

        .el-icon {
            height: 25px;
            transition: .5s;
        }

    }

    .ups {
        color: var(--primary-color);
        background: #fff;

        .el-icon {
            color: var(--primary-color);
        }

        &:hover {
            color: #fff;
            background: var(--primary-color);

            .el-icon {
                color: #fff;
            }
        }
    }
}
</style>